package com.netx.cubigraf.servlets;
import java.io.IOException;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import com.netx.ebs.EbsRequest;
import com.netx.ebs.EbsResponse;
import com.netx.ebs.Session;


public class SrvServicoEditarCopiar extends CubigrafServlet {

	public SrvServicoEditarCopiar() {
		super("servico-editar");
	}

	protected void doGet(EbsRequest request, EbsResponse response) throws IOException {
		Session s = request.getUserSession();
		Long totalSize;
		Long bytesWritten;
		synchronized(s) {
			totalSize = (Long)s.getAttribute(ForegroundCopy.FILE_COPY_SIZE);
			bytesWritten = (Long)s.getAttribute(ForegroundCopy.FILE_COPY_BYTES_WRITTEN);
		}

		if(totalSize == null) {
			totalSize = bytesWritten = new Long(0);
		}

		Document document = DocumentHelper.createDocument();
		Element root = document.addElement("netx-application-data");
		root.addAttribute("status", "ok");
		Element user = root.addElement("copy");
		user.addElement("total-size").setText(totalSize.toString());
		user.addElement("bytes-written").setText(bytesWritten.toString());

		response.setContentType("text/xml");
		response.sendDisableCache();
		document.write(response.getWriter());
	}
}
